<template>
	<view>
		<view class="news_item" v-for="item in list" :key="item.id" @click="navigator(item.id)">
			<image :src="item.img_url? '../../static/shouji.jpg': 'item.img_url'" mode=""></image>
			<view class="right">
				<view class="tit">{{item.title}}</view>
				<view class="info">
					<text>发表时间：{{item.add_time | formatDate}}</text>
					<text>浏览：{{item.click}}</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default{
		props:['list'], //list是自定义组件的属性
		filters:{
			formatDate(date){
				console.log(date)
				const nDate=new Date(date)
				const year=nDate.getFullYear()
				const month=(nDate.getMonth()+1).toString().padStart(2,0)	
				const ndate=nDate.getDate().toString().padStart(2,0)
				console.log()
				return year+'-'+month+'-'+ndate 
			}
		},
		methods:{
			navigator (id) {
				// console.log(id)
				this.$emit('itemClick',id)//点击就触发父组件的这个事件 
			},
		}
	}
</script>

<style lang="scss">
	.news_item{
		display: flex;
		padding: 10rpx 20rpx;
		border-bottom: 1px solid $shop-color;
		image{
			min-width: 200rpx;
			max-width: 200rpx;
			height: 150rpx;
		}
		.right{
			display: flex;
			flex-direction: column;//列排
			justify-content: space-between;//盒子上下距离一样宽度
			margin-left: 15rpx;
			.tit{
				font-size: 30rpx;
			}
			.info{
				font-size: 24rpx;
				text:nth-child(2){
					margin-left: 30rpx;
				}
			}
		}
	}
</style>
